package com.neutech.web;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * ${陈虎}
 * 13:10
 * wp_servlet_day01
 * ${"Do what you say,say what you do"}
 */

public class HelloServlet extends HttpServlet {
    @Override
    public void init() throws ServletException {
        System.out.println("初始化一次init()方法");
    }

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        System.out.println("进入到该类中");
        // 从前端或取数据的编码集
        request.setCharacterEncoding("utf-8");
        // 服务器端向前端返回数据的编码集
        response.setContentType("text/html;charset =utf-8 ");
        response.getWriter().println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "<br>");
        response.getWriter().println("<h1 style = 'color:red'>你好</h1>");
    }

    @Override
    public void destroy() {
        System.out.println("结束调用了destroy()方法");
    }
}
